package com.hyuga.controller;

import com.hyuga.annotation.MyController;
import com.hyuga.annotation.MyRequestMapping;
import com.hyuga.annotation.MyRequestParam;
import com.hyuga.annotation.MyResource;
import com.hyuga.service.TestService;
import com.hyuga.service.TestService2;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author hyuga
 * @date 2018-06-21 21:36
 */
@MyController
@MyRequestMapping("/test")
public class TestController {

    @MyResource
    private TestService testService;

    @MyResource
    private TestService2 testService2;

    private static final String LOVE = "testLove";

    @MyRequestMapping("/doTest")
    public void test1(HttpServletResponse response, @MyRequestParam("param") String param) {
        System.out.println(param);
        try {
            response.getWriter().write("doTest method success! param:" + param);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @MyRequestMapping("/doTest2")
    public void test2(HttpServletResponse response) {
        try {
            response.getWriter().println("doTest2 method success!");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @MyRequestMapping("/doTest3")
    public void test3(HttpServletResponse response) {
        try {
            InputStream resourceAsStream = this.getClass().getClassLoader().getResourceAsStream("test/application.properties");
            Properties properties = new Properties();
            properties.load(resourceAsStream);
            System.out.println(properties.get("scanPackage"));
            System.out.println(Integer.valueOf(properties.get("love").toString()));

            int random = testService.getRandom();
            response.getWriter().println("random number is:" + random);
            response.getWriter().println("love:" + LOVE);
            response.getWriter().println("random2 number is:" + testService2.getRandom2());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}